package cn.kgc.http;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpServerCodec;

/**
 * @author YC
 * Http服务的初始化器，给socketChannel设置Handler，用于处理Http请求和响应
 */
public class HttpServerInitializer extends ChannelInitializer<SocketChannel> {

    @Override
    protected void initChannel(SocketChannel channel) throws Exception {
        // 获取管道
        ChannelPipeline pipeline = channel.pipeline();
        // 添加HTTP编解码器，用于处理HTTP请求和响应的编码解码
        pipeline.addLast(new HttpServerCodec());
        // 添加自定义的HTTP请求处理器
        pipeline.addLast(new HttpServerHandler());
    }

}
